package Gui.Dialogs;

import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import Cards.Card;
import Gui.GameFrame;
import Main.Defines;

public class ViewDealCardsDialog extends JDialog {
	/**
	 * 
	 */

	private static final long serialVersionUID = 2082934973698187125L;
	private JPanel jp;

	public void buildUIContents() {
		for (Card i : Defines.CP().getDealCards()) {
			JLabel mailLabel = new JLabel(i.toString());
			jp.add(mailLabel);
		}

		if (Defines.CP().getDealCards().size() == 0) {
			JLabel noDealCards = new JLabel("Player has no deal cards");
			jp.add(noDealCards);
		}

		JButton ok = new JButton("OK");

		ok.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub

				dispose();
				GameFrame.getInstance().update();
			}
		});
		jp.add(ok);
	}

	public ViewDealCardsDialog() {
		setModalityType(getModalityType().APPLICATION_MODAL);
		jp = new JPanel();
		jp.setBorder(Defines.getEmptyBorderConstraints());
		jp.setLayout(new GridLayout(0, 1, 0, 5

		));
		
		buildUIContents();

		add(jp);
		pack();

		if (getTitle() != null) {
			FontMetrics fm = getFontMetrics(getFont());
			int width = fm.stringWidth(getTitle()) + Defines.ICON_WIDTH;
			width = (int) Math.max(width * 1.2, getPreferredSize().getWidth());
			setSize(new Dimension(width, getHeight()));
		}
		setLocationRelativeTo(GameFrame.getInstance());
		setVisible(true);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

	}
}
